package ac.il.technion.c236369.hw4.core;

import org.apache.log4j.Logger;


/**
 * @author Artem Barger, Maxim Aizenshtein.
 *
 * General purpose class template for later use for
 * SocketReader implementation and RequestHandler classes. 
 *
 */
public abstract class ServerRunnableEntity implements Runnable {

	private boolean terminated = false;
	protected Logger log = null;

	protected void setUpLogger( Logger logger) {
		log = logger;
	}
	
	@Override
	public void run() {
		while( !terminated ) {
			try {
				Thread.sleep( 5 * 100);
				runImpl( );
			} catch (InterruptedException e) {
				log.error(e);
			}
		}	
	}

	/**
	 * Abstract method to implement by child classes.
	 */
	abstract public void runImpl();

	public void terminate( ) {
		terminated = true;
	}
	
}
